using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DevExpress.Web.ASPxTabControl;
using DevExpress.Web.ASPxNewsControl;
using Indeco.G24.Data;
using Indeco.G24.Data.SqlClient;
using Indeco.G24.Entities;
namespace Indeco.G24.Website.News
{
    public partial class News : System.Web.UI.Page
    {
        public string ID;
        protected void Page_Load(object sender, EventArgs e)
        {
            string IdTinTuc = Request.Params["IDTinTuc"];
            string  sqlTieuDiem, sqlSuKien,sqlNewsOther,sqlFindDanhmuc;
            if (!string.IsNullOrEmpty(IdTinTuc))
            {
                int outcount;
                ID = IdTinTuc;
                sqlTieuDiem = "id_tintuc in (select id_tintuc from tb_tintuctieudiem) and id_tintucdanhmuc in (select id_tintucdanhmuc from tb_tintuc where id_tintuc='" + IdTinTuc + "') and id_tintuc <> '"+IdTinTuc+"' and nhacungcap is null";
                sqlSuKien = "id_tintuc in (select id_tintuc from tb_tintucsukien) and id_tintucdanhmuc in (select id_tintucdanhmuc from tb_tintuc where id_tintuc='" + IdTinTuc + "') and id_tintuc <> '" + IdTinTuc + "' and nhacungcap is null";
                sqlFindDanhmuc = "";
                sqlNewsOther = "id_tintucdanhmuc not in (select id_tintucdanhmuc from tb_tintuc where id_tintuc='" + IdTinTuc + "') and id_tintucdanhmuc in (select id_tintucdanhmuc from tb_tintucdanhmuc where id_tintucdanhmuccha in (select id_tintucdanhmuccha from tb_tintucdanhmuc where id_tintucdanhmuc in (select id_tintucdanhmuc from tb_tintuc where id_tintuc='" + IdTinTuc + "')))";
                TList<TinTuc> tintieudiem = DataRepository.TinTucProvider.GetPaged(sqlTieuDiem, "thoidiemcapnhat DESC", 0, 5, out outcount);
                datalistTieuDiem.DataSource = tintieudiem;
                datalistTieuDiem.DataBind();
                TList<TinTuc> tinsukien = DataRepository.TinTucProvider.GetPaged(sqlSuKien, "thoidiemcapnhat DESC", 0, 5, out outcount);
                datalistSuKien.DataSource = tinsukien;
                datalistSuKien.DataBind();
                TList<TinTucDanhMuc> tinOther = DataRepository.TinTucDanhMucProvider.GetPaged(sqlNewsOther,"", 0, 10, out outcount);
                listNews.DataSource = tinOther;
                listNews.DataBind();                
            }
        }
        protected void DataListGetNewsByID_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            DataList list = (DataList)e.Item.FindControl("datalistOtherNews");
            if (!string.IsNullOrEmpty(ID) && list!=null)
            {
                int outcount;
                string  sqlOtherNews = "id_tintucdanhmuc in (select id_tintucdanhmuc from tb_tintuc where id_tintuc='" + ID + "') and id_tintuc <> '" + ID + "'";
                TList<TinTuc> tinKhac = DataRepository.TinTucProvider.GetPaged(sqlOtherNews, "thoidiemcapnhat DESC", 0, 10, out outcount);
                list.DataSource = tinKhac;
                list.DataBind();
            }
        }
        protected void listNews_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            Label lb = (Label)e.Item.FindControl("IDTinTucDanhMuc");
            DataList list = (DataList)e.Item.FindControl("datalistNewsOther");
            string sql;
            int outcount;
            if (lb != null && list != null)
            {
                sql = "id_tintucdanhmuc = '"+lb.Text+"'";
                TList<TinTuc> tin = DataRepository.TinTucProvider.GetPaged(sql, "thoidiemcapnhat DESC", 0, 5, out outcount);
                list.DataSource = tin;
                list.DataBind();
            }
        }
    }
}
